﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Feedback.Business;
using Feedback.Global;
using FeedbackWebClient.Common;

namespace FeedbackWebClient
{
    public partial class Login : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            int businessId = -1;
            if (new BusinessLogic().IsValidBusiness(UserName.Text.Trim(), CryptographyHelper.CreateMD5Hash(Password.Text), ref businessId))
            {
                StateHelper.BusinessId = businessId;
                StateHelper.BusinessEmail = UserName.Text;
                FormsAuthentication.RedirectFromLoginPage(UserName.Text, false);
                Response.Redirect("~/FeedbackView.aspx");
            }
            else
            {
                FailureText.Text = "Incorrect email or password.";
            }
        }
    }
}